<?php
namespace admin\Controller;
use Think\Controller;
class ArticleController extends CommonController {
	public function lists(){
		$key = I('request.key','','trim');
		$audit = I('request.audit','','trim');
		$excellent = I('request.excellent','','trim');
		$sort='id DESC';
		if ($key)
		{
			$key_type = I('request.key_type',0,'intval');
			if ($key_type=='1')
			{
				$map['title'] = array('like','%'.$key.'%');
			}
			if ($key_type=='2')
			{
				$map['content'] = array('like','%'.$key.'%');
			}
			if ($key_type=='3')
			{
				$map['uid'] = intval($key);
			}
		}
		if ($audit<>'')
		{
			$map['audit'] = intval($audit);
		}
		if ($excellent<>'')
		{
			$map['excellent'] = intval($excellent);
		}		
		$list=D('Article')->get_list($map,true,$sort,10,true);
		$this->assign('lists',$list);
		$this->display();
	}
//修改审核
public function audit(){
	
		$ids = I('request.id');
		$audit=I('request.audit','0','intval');
		$ids = is_array($ids)?implode(",",$ids):$ids;	
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$map['id']     = array('IN',$ids);
			$data['audit'] = intval($audit);
			M('Article')->where($map)->save($data);
			if ($audit==-1)
			{
				//重新统计问题总数
				$info=M('Article')->where($map)->select();
				foreach($info as $val)
				{
					$uids[]=$val['uid'];
				}
				D('User')->update_count($uids,2);
			}
			$this->success("设置成功！");
		}
		else
		{
			$this->error('请选择项目！');
		}
	
}
//修改文章属性
public function exc(){
	
		$ids = I('request.id');
		$excellent=I('request.excellent','0','intval');
		$ids = is_array($ids)?implode(",",$ids):$ids;	
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$map['id']     = array('IN',$ids);
			$data['excellent'] = intval($excellent);
			M('Article')->where($map)->save($data);
			$this->success("设置成功！");
		}
		else
		{
			$this->error('请选择项目！');
		}
	
}
public function delete(){
	
		$ids = I('request.id');
		$ids = is_array($ids)?implode(",",$ids):$ids;
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$map['id']     = array('IN',$ids);
			$info=M('Article')->where($map)->select();
			foreach($info as $val)
				{
					$uids[]=$val['uid'];
			}
			//获取标签
			$tagmap['qid']     = array('IN',$ids);
			$tags=M('ArticleTag')->where($tagmap)->select();
			foreach($tags as $t)
			{
					$set_tag[]=$t['tagid'];
			}
			$s=D("Article")->del_article($ids);
			//更新标签统计
			D('Tag')->set_tag_count($set_tag,'count_article','dec');
			//更新会员文章统计
			D('User')->update_count($uids,2);
			$this->success("成功删除");
		}
		else
		{
		$this->error('请选择要删除的信息！');
		}
	
 	}
 
}
?>